﻿#Region " Imports "

Imports System.Data
Imports BlazeApps.Library.Forum

#End Region

Partial Class Usercontrols_Forum_RecentActivity
	Inherits UserControlBase

#Region " Enums, Memebers and Properties "

	Private ForumCheck As New ForumChecks
	Private DataPageLocal As New PagedDataSource

	Public Property sortCriteria() As String
		Get
			Return CStr(ViewState("sortCriteria"))
		End Get

		Set(ByVal Value As String)
			ViewState("sortCriteria") = Value
		End Set
	End Property

	Public Property sortDir() As String
		Get
			Return CStr(ViewState("sortDir"))
		End Get

		Set(ByVal Value As String)
			ViewState("sortDir") = Value
		End Set
	End Property

	Protected Property BoardGuid() As Guid
		Get
			Return GetGuidFromVS("BoardID")
		End Get
		Set(ByVal value As Guid)
			ViewState.Add("BoardID", value)
		End Set
	End Property

	Protected Property CategoryGuid() As Guid
		Get
			Return GetGuidFromVS("CategoryID")
		End Get
		Set(ByVal value As Guid)
			ViewState.Add("CategoryID", value)
		End Set
	End Property

	Protected Property ForumGuid() As Guid
		Get
			Return GetGuidFromVS("ForumID")
		End Get
		Set(ByVal value As Guid)
			ViewState.Add("ForumID", value)
		End Set
	End Property

	Protected Property TopicGuid() As Guid
		Get
			Return GetGuidFromVS("TopicID")
		End Get
		Set(ByVal value As Guid)
			ViewState.Add("TopicID", value)
		End Set
	End Property

	Protected Property BoardName() As String
		Get
			Return GetStringFromVS("BoardName")
		End Get
		Set(ByVal value As String)
			ViewState.Add("BoardName", value)
		End Set
	End Property

	Protected Property CategoryName() As String
		Get
			Return GetStringFromVS("CategoryName")
		End Get
		Set(ByVal value As String)
			ViewState.Add("CategoryName", value)
		End Set
	End Property

	Protected Property ForumName() As String
		Get
			Return GetStringFromVS("ForumName")
		End Get
		Set(ByVal value As String)
			ViewState.Add("ForumName", value)
		End Set
	End Property

	Protected Property TopicName() As String
		Get
			Return GetStringFromVS("TopicName")
		End Get
		Set(ByVal value As String)
			ViewState.Add("TopicName", value)
		End Set
	End Property

	Protected Property ForumLocked() As Boolean
		Get
			Return GetBooleanFromVS("Locked")
		End Get
		Set(ByVal value As Boolean)
			ViewState.Add("Locked", value)
		End Set
	End Property

	Protected Property ForumModerated() As Boolean
		Get
			Return GetBooleanFromVS("ForumModerated")
		End Get
		Set(ByVal value As Boolean)
			ViewState.Add("ForumModerated", value)
		End Set
	End Property

#End Region

#Region " Page Events "

	Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
		Me.MessageLabel = Me.uxMessagesLabel
	End Sub

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		If Me.Page.IsPostBack = False Then

			'Set Default Sort Order and Direction
			Me.sortCriteria = "LastPostDate"
			Me.sortDir = "DESC"

		End If

		If Me.Page.IsPostBack = False Then
			BindDataItems()
		End If

	End Sub

#End Region

#Region " Save Data "

#End Region

#Region " Load Data "

	Public Overloads Overrides Sub BindDataItems()

		Dim List As New TopicList
		Dim DT As New DataTable
		Dim DV As New DataView

		DT = List.GetActiveTopics()

		Me.RecordCount = DT.Rows.Count

		DV.Table = DT

		DV.Sort = Me.sortCriteria & " " & Me.sortDir

		With Me.uxTopicRepeater
			.DataSource = DV
			.DataBind()
		End With

	End Sub

#End Region

#Region " Form Controls Events "

	Protected Sub LoadPosts(ByVal sender As Object, ByVal e As CommandEventArgs)
		Response.Redirect(String.Format("forum.aspx?pid=for_post&topicid={0}&forumid={1}", e.CommandArgument.ToString, ForumGuid))
	End Sub

	Protected Sub uxTopicRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles uxTopicRepeater.ItemDataBound
		Dim item As RepeaterItem = e.Item
		Dim Icon As Image = CType(item.FindControl("uxStatusImage"), Image)

		If (item.ItemType = ListItemType.Item) OrElse (item.ItemType = ListItemType.AlternatingItem) Then
			If ShowItem(ConvertToGuid(e.Item.DataItem("ForumID").ToString)) = True Then
				If CType(item.DataItem("locked").ToString, Boolean) Then
					Icon.ImageUrl = String.Format("~/App_Themes/{0}/images/icons/topic_lock.gif", Page.Theme.ToString)
					ForumLocked = True
				Else
					Icon.ImageUrl = String.Format("~/App_Themes/{0}/images/icons/topic.gif", Page.Theme.ToString)
					ForumLocked = False
				End If
			Else
				item.Visible = False
			End If
		End If
	End Sub

#End Region

#Region " Helpers and Methods "


#End Region

End Class
